package com.qqclient.service;

import com.qqcommon.Message;
import com.qqcommon.MessageType;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.Date;

//发送消息服务
public class MessageClinetService {
    public void sendMessageToOne(String content,String sender,String getterId) throws IOException {
        Message message = new Message();
        message.setMesType(MessageType.MESSAGE_COM_MES);
        message.setSender(sender);
        message.setGetter(getterId);
        message.setContent(content);
        message.setSendTime(new Date().toString());
        System.out.print(sender+" 对 "+getterId+" 说 ："+content);
        ObjectOutputStream oos = new ObjectOutputStream(ManageClinentConnectServerThrend.getClinentConnectServerThrend(sender).getSocket().getOutputStream());
        oos.writeObject(message);
    }
    public void sendMessageAll(String content,String sender) throws IOException {
        Message message = new Message();
        message.setMesType(MessageType.MESSAGE_TO_ALL_MES);
        message.setSender(sender);
        message.setContent(content);
        message.setSendTime(new Date().toString());
        System.out.print(sender+"对所有人说 ："+content);
        ObjectOutputStream oos = new ObjectOutputStream(ManageClinentConnectServerThrend.getClinentConnectServerThrend(sender).getSocket().getOutputStream());
        oos.writeObject(message);
    }
}
